#ifndef WINREMOCON_H
#define WINREMOCON_H

#include <QDialog>
#include <QMap>
#include <QList>
#include <QSystemTrayIcon>

#include "ui_ConfigDialog.h"

#define DEFAULT_PORT	7378

typedef enum
{
	LogError = 0, LogWarn, LogDebug,
} LogLevel;

class QUdpSocket;
class QSystemTrayIcon;
class QMenu;
class QCloseEvent;
class QSettings;

class WinRemocon: public QDialog
{
	Q_OBJECT
	
public:
	WinRemocon(QWidget *parent = NULL);
	virtual ~WinRemocon();

public:
	virtual void reject();
	
protected:
	void closeEvent(QCloseEvent *);

protected slots:
	void saveSettings();
	
	void trayIconActivated(QSystemTrayIcon::ActivationReason);

private:
	QUdpSocket *socket;
	
	QSettings *settings;
	
	// tray icon
	QSystemTrayIcon *trayIcon;
	QMenu *trayIconMenu;
	
	void setupContextMenu();
	
	Ui::ConfigDialog ui;
	
	typedef QList<unsigned char> KeyCombination;
	typedef QMap<int, KeyCombination> KeyMap;
	KeyMap standardKeyMap, japaneseKeyMap;

private slots:
	void setupKeyMaps();
	
	void readPendingDatagrams();
	
	void allowClient();
	void denyClient();
	
	void saveLog();
	
	void changePort();
	
	void appendLog(const QString &, LogLevel level = LogDebug);
	
	void checkStartupState();
	void toggleStartupCurrentUser(bool);
	void toggleStartupAllUsers(bool);
};

#endif	// WINREMOCON_H
